package com.cat.twoPointerTechnique;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/split-two-strings-to-make-palindrome/
 * @create 2025/8/2 14:04
 * @since JDK17
 */

public class Solution05 {
    public boolean checkPalindromeFormation(String a, String b) {
        char[] s1 = a.toCharArray(), s2 = b.toCharArray();
        return judge(s1, s2) || judge(s2, s1);
    }

    public boolean judge(char[] s1, char[] s2) {
        int i, j;
        for (i = 0, j = s1.length - 1; i < j && s1[i] == s2[j]; i++, j--) ;
        if (i >= j) {   //
            return true;
        }
        int l = i, r = j;
        for (; i < j && s1[i] == s1[j]; i++, j--);
        if (i >= j) return true;
        for (; l < r && s2[l] == s2[r]; l++, r--);
        if (l >= r) return true;
        return false;
    }
}
